package com.css.zfzx.sjcj.modules.drill.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.bpm.platform.utils.PlatformPageUtils;
import com.css.zfzx.sjcj.modules.drill.Entity.QhY18Entity;
import com.css.zfzx.sjcj.modules.drill.service.QhY18Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Li Helei
 * @date 2020-11-11
 */
@Slf4j
@RestController
@RequestMapping("/qh/qhY18")
public class QhY18Controller {
    @Autowired
    private QhY18Service qhY18Service;

    @GetMapping("/queryQhY18s")
    public RestResponse queryQhY18s(HttpServletRequest request, String drillId) {
        RestResponse response = null;
        try{
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            JSONObject jsonObject = qhY18Service.queryQhY18s(drillId,curPage,pageSize);
            response = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    /*@PostMapping("/queryQhY18sNoPage")
    public RestResponse queryQhY18sNoPage(@RequestBody QhY18QueryParams queryParams) {
        RestResponse response = null;
        try{
            JSONObject jsonObject = qhY18Service.queryQhY18s(queryParams);
            response = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }*/

    @GetMapping("{id}")
    public RestResponse getQhY18(@PathVariable String id) {
        RestResponse response = null;
        try{
            QhY18Entity qhY18 = qhY18Service.getQhY18(id);
            response = RestResponse.succeed(qhY18);
        }catch (Exception e){
            String errorMessage = "获取失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @PostMapping("/save")
    public RestResponse saveQhY18(@RequestBody QhY18Entity qhY18) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY18Service.saveQhY18(qhY18);
            json.put("message", "新增成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "新增失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;

    }
    @PostMapping("/update")
    public RestResponse updateQhY18(@RequestBody QhY18Entity qhY18)  {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY18Service.updateQhY18(qhY18);
            json.put("message", "修改成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "修改失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @PostMapping("/delete")
    public RestResponse deleteQhY18s(@RequestBody String ids) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY18Service.deleteQhY18s(ids);
            json.put("message", "删除成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "删除失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    @PostMapping("/submit/{ids}")
    public RestResponse submitQhY18(@PathVariable String ids)  {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY18Service.submitQhY18(ids);
            json.put("message", "提交成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "提交失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

}